﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【数据部门】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto数据部门
    /// </summary>
    public abstract class AutoDataDepartmentMapping : BaseMapping<DataDepartment, DataDepartmentModel, DataDepartmentFilterModel>
    {
        public AutoDataDepartmentMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override DataDepartmentModel Entity2Model(DataDepartment entity)
        {
            DataDepartmentModel model = new DataDepartmentModel();

            model.DataDepartmentID = entity.DataDepartmentID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Type = entity.Type;
            model.DataID = entity.DataID;
            model.DepartmentID = entity.DepartmentID;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override DataDepartment Model2Entity(DataDepartmentModel model)
        {
            DataDepartment entity = new DataDepartment();

            entity.DataDepartmentID = model.DataDepartmentID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Type = model.Type;
            entity.DataID = model.DataID;
            entity.DepartmentID = model.DepartmentID;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<DataDepartment> FilterModel2Where(DataDepartmentFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._DataDepartmentID.HasValue)
            {
                where = where.And(x => x.DataDepartmentID == filterModel._DataDepartmentID.Value);
            }
            if (filterModel._DataDepartmentIDs.IsNotEmpty() && filterModel._DataDepartmentIDs.Count > 0)
            {
                where = where.And(x => filterModel._DataDepartmentIDs.Contains(x.DataDepartmentID));
            }
            if (filterModel._NotDataDepartmentIDs.IsNotEmpty() && filterModel._NotDataDepartmentIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotDataDepartmentIDs.Contains(x.DataDepartmentID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //类型
            if (filterModel._Type.HasValue)
            {
                where = where.And(x => x.Type == filterModel._Type.Value);
            }
            if (filterModel._Types.IsNotEmpty() && filterModel._Types.Count > 0)
            {
                where = where.And(x => filterModel._Types.Contains(x.Type));
            }
            if (filterModel._NotTypes.IsNotEmpty() && filterModel._NotTypes.Count > 0)
            {
                where = where.And(x => !filterModel._NotTypes.Contains(x.Type));
            }

            return where;
        }
        #endregion
    }
}

